//
//  TVRechargeHeaderView.swift
//  StarTimesON
//
//  Created by Toj on 12/2/22.
//  Copyright © 2022 StarTimes. All rights reserved.
//

import UIKit

class TVRechargeHeaderView: UICollectionReusableView {
    
    var cardInfo: NSObject? { didSet {
        
    } }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        addSubview(cardIDTextField)
        addSubview(spaceView)
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        cardIDTextField.snp.makeConstraints { make in
            make.left.right.equalTo(self).inset(16)
            make.top.equalTo(14)
            make.bottom.equalTo(self).inset(24)
        }
        
        spaceView.snp.makeConstraints { make in
            make.left.right.bottom.equalTo(self)
            make.height.equalTo(8)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private lazy var spaceView: UIView = {
        let view = UIView()
        view.backgroundColor = "#EEEEEE".to_color
        return view
    }()
    
    private(set) lazy var rightView: UIButton = {
        let view = UIButton()
        view.adjustsImageWhenHighlighted = false
        view.setImage("commodity_tv_cardHistory".to_image, for: .normal)
        view.frame.size = CGSize(width: 24, height: 24)
        return view
    }()
    
    private(set) lazy var cardIDTextField: FMTextField = {
        let view = setupTextField()
        view.backgroundColor = .white
        let maxCharCount = 11
        view.maxCharCount = maxCharCount
        view.charFormatType = .fourFourThree
        
        view.titleLabel.text = "Smart Card ID :"
        view.textField.returnKeyType = .next
        
        view.rightView = rightView
        view.stringValue = "012345678910"
        return view
    }()
    
    private func setupTextField() -> FMTextField {
        let view = FMTextField()
        view.delegate = self
        
        view.titleLabel.textColor = "#AAAAAA".to_color
        view.titleLabel.font = UIFont.systemFont(ofSize: 14)
        
        view.textField.keyboardType = .numberPad
        view.textField.clearButtonMode = .whileEditing // 清空按钮
        view.textField.font = UIFont.boldSystemFont(ofSize: 20)
        view.textField.textColor = "#333333".to_color
        
        view.maxCharLabel.textColor = "#999999".to_color
        view.maxCharLabel.font = UIFont.systemFont(ofSize: 12)
        
        return view
    }
}

// MARK: - 代理事件
extension TVRechargeHeaderView: FMTextFieldDelegate {
    
    func textFieldEditingChange(_ view: FMTextField, text: String, validText: String) {
        
    }
}
